home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / vgl20.zip / VGLMOUSE.C < prev    next >
C/C++ Source or Header  |  1993-05-14  |  3KB  |  120 lines

  1. /*****************************************************************************
  2.  VGLMOUSE.C
  3.  
  4.  Simple routines for mouse handling.  Nothing special, but somebody asked
  5.  for them.  Should work with all Microsoft compatible mice.
  6.  
  7.  Mark
  8.  morley@camosun.bc.ca
  9. *****************************************************************************/
  10.  
  11. #include <dos.h>
  12.  
  13. static int Mouse = 0;                   /* Whether or not we have a mouse   */
  14. static int Hidden = 0;                  /* Whether or not it's hidden       */
  15.  
  16. /*****************************************************************************
  17.  Returns 1 if there is a mouse attached, 0 if not.  You must have first
  18.  called vglMouseInit()
  19. *****************************************************************************/
  20. int vglMousePresent()
  21. {
  22.    return Mouse;
  23. }
  24.  
  25. /*****************************************************************************
  26.  Initialize the mouse (if it exists).  Returns 1 if the mouse exists, 0 if
  27.  it doesn't.  By default the mouse is hidden and must be explicitly turned
  28.  on (vglShowMouse)
  29. *****************************************************************************/
  30. int vglInitMouse()
  31. {
  32.    union REGS r;
  33.  
  34.    r.x.ax = 0;
  35.    int86( 0x33, &r, &r );
  36.    if( r.x.ax )
  37.    {
  38.       Mouse = 1;
  39.       r.x.ax = 0x1c;
  40.       r.x.bx = 1;
  41.       int86( 0x33, &r, &r );
  42.    }
  43.    else
  44.       Mouse = 0;
  45.    Hidden = 1;
  46.    return Mouse;
  47. }
  48.  
  49. /*****************************************************************************
  50.  Turns on the mouse cursor.
  51. *****************************************************************************/
  52. int vglShowMouse()
  53. {
  54.    union REGS r;
  55.  
  56.    if( Mouse && Hidden )
  57.    {
  58.       r.x.ax = 1;
  59.       int86( 0x33, &r, &r );
  60.       Hidden = 0;
  61.       return 1;
  62.    }
  63.    return 0;
  64. }
  65.  
  66. /*****************************************************************************
  67.  Hides the mouse cursor.
  68. *****************************************************************************/
  69. int vglHideMouse()
  70. {
  71.    union REGS r;
  72.  
  73.    if( Mouse && !Hidden )
  74.    {
  75.       r.x.ax = 2;
  76.       int86( 0x33, &r, &r );
  77.       Hidden = 1;
  78.       return 1;
  79.    }
  80.    return 0;
  81. }
  82.  
  83. /*****************************************************************************
  84.  Hides the mouse cursor if it lies within the specified rectangle.
  85. *****************************************************************************/
  86. int vglHideMouseIf( int x1, int y1, int x2, int y2 )
  87. {
  88.    int x, y, b;
  89.  
  90.    if( Mouse && !Hidden )
  91.    {
  92.       vglGetMouseInfo( &x, &y, &b );
  93.       if( x >= x1 && x <= x2 && y >= y1 && y <= y2 )
  94.          return( vglHideMouse() );
  95.    }
  96.    return 0;
  97. }
  98.  
  99. /*****************************************************************************
  100.  Returns the mouse status.  It's X and Y position is returned in 'x' and 'y',
  101.  and its button status is returned in 'b'.
  102. *****************************************************************************/
  103. int vglGetMouseInfo( int* x, int* y, int* b )
  104. {
  105.    union REGS r;
  106.  
  107.    if( Mouse )
  108.    {
  109.       r.x.ax = 3;
  110.       int86( 0x33, &r, &r );
  111.       *b = r.x.bx;
  112.       *x = r.x.cx;
  113.       *y = r.x.dx;
  114.       return *b;
  115.    }
  116.    else
  117.       return 0;
  118. }
  119.  
  120.